package part14;

/**
 * @author wcj
 * @Date 2021/5/25 18:40
 * @Version 1.0
 */
public class Part142 {

    /**
     * class对象仅仅在需要的时候才进行加载
     *
     * @param args
     */
    public static void main(String[] args) {
        System.out.println("inside main");
        new Candy();
        System.out.println("After create Candy");
        try {
            // 所有的class对象都属于Class这个类，forName()方法为其的一个静态方法
            Class.forName("Gum");
        } catch (ClassNotFoundException e) {
            System.out.println("can't find Gum");
        }
        System.out.println("After Class.forName('Gum')");
        new Cookie();
        System.out.println("After create Cookie");
    }
}

class Candy {
    static {
        System.out.println("Loading Candy");
    }
}

class Gum {
    static {
        System.out.println("Loading Gum");
    }
}

class Cookie {
    static {
        System.out.println("Loading Cookie");
    }
}